#ifndef INFINITY_MATERIAL_LIBRARY_H
#	define INFINITY_MATERIAL_LIBRARY_H

#include "material.h"

namespace infinity {

class MaterialLibrary
{
public : //! @name Cosntants
	//! @{
	static const dw::uint32 MaterialsMaxCount = 256;
	//! @}

public : //! @name Construction & Destruction
	//! @{
	MaterialLibrary()
	{
		m_materials[0].setName("void");
		m_materials[0].setColor(dw::graphics::Colorf::White);
		m_materials[0].setOffsetAll(dw::maths::Vector2f(-1,-1));
		m_materials[0].setIsVoid(true);
		m_materials[0].setToughness(100.f);
		m_materials[0].setSpawn(Material::NOTHING);
		m_materials[0].setSpawnMax(0);
		m_materials[0].setIdSpawn(0);

		m_materials[1].setName("grass");
		m_materials[1].setColor(dw::graphics::Colorf::Green);
		m_materials[1].setOffsetTop(dw::maths::Vector2f(0.0f,0.0f));
		m_materials[1].setOffsetSide(dw::maths::Vector2f(7/16.0f,6/16.0f));
		m_materials[1].setOffsetSide2(dw::maths::Vector2f(7/16.0f,6/16.0f));
		m_materials[1].setOffsetBottom(dw::maths::Vector2f(6/16.0f,6/16.0f));
		m_materials[1].setIsVoid(false);
		m_materials[1].setToughness(0.1f);
		m_materials[1].setSpawn(Material::BLOC);
		m_materials[1].setSpawnMax(1);
		m_materials[1].setIdSpawn(2);

		m_materials[2].setName("dirt");
		m_materials[2].setColor(dw::graphics::Colorf::Brown);
		m_materials[2].setOffsetAll(dw::maths::Vector2f(6/16.0f,6/16.0f));
		m_materials[2].setIsVoid(false);
		m_materials[2].setToughness(0.1f);
		m_materials[2].setSpawn(Material::BLOC);
		m_materials[2].setSpawnMax(1);
		m_materials[2].setIdSpawn(2);

		m_materials[3].setName("stone");
		m_materials[3].setColor(dw::graphics::Colorf::Grey);
		m_materials[3].setOffsetAll(dw::maths::Vector2f(1/16.0f,3/16.0f));
		m_materials[3].setIsVoid(false);
		m_materials[3].setToughness(0.3f);
		m_materials[3].setSpawn(Material::BLOC);
		m_materials[3].setSpawnMax(1);
		m_materials[3].setIdSpawn(3);		// todo :faire la diff entre stone et cobolstone 

		m_materials[4].setName("sand");
		m_materials[4].setColor(dw::graphics::Colorf::Yellow);
		m_materials[4].setOffsetAll(dw::maths::Vector2f(4/16.0f,0.0f));
		m_materials[4].setIsVoid(false);
		m_materials[4].setToughness(0.1f);
		m_materials[4].setSpawn(Material::BLOC);
		m_materials[4].setSpawnMax(1);
		m_materials[4].setIdSpawn(4);

		m_materials[5].setName("wood");
		m_materials[5].setColor(dw::graphics::Colorf::Brown);
		m_materials[5].setOffsetTop(dw::maths::Vector2f(7/16.0f,0.0f));
		m_materials[5].setOffsetSide(dw::maths::Vector2f(6/16.0f,0.0f));
		m_materials[5].setOffsetBottom(dw::maths::Vector2f(7/16.0f,0.0f));
		m_materials[5].setIsVoid(false);
		m_materials[5].setToughness(0.2f);
		m_materials[5].setSpawn(Material::BLOC);
		m_materials[5].setSpawnMax(1);
		m_materials[5].setIdSpawn(5);

		m_materials[6].setName("leaves");
		m_materials[6].setColor(dw::graphics::Colorf::Green);
		m_materials[6].setOffsetAll(dw::maths::Vector2f(8/16.0f,0.0f));
		m_materials[6].setIsVoid(false);
		m_materials[6].setAlphaBlend(true);
		m_materials[6].setToughness(0.1f);
		m_materials[6].setSpawn(Material::ITEM);
		m_materials[6].setSpawnMax(1);
		m_materials[6].setIdSpawn(5);

		m_materials[7].setName("gold");
		m_materials[7].setColor(dw::graphics::Colorf::Gold);
		m_materials[7].setOffsetAll(dw::maths::Vector2f(11/16.0f,9/16.0f));
		m_materials[7].setIsVoid(false);
		m_materials[7].setToughness(0.3f);
		m_materials[7].setSpawn(Material::ITEM);
		m_materials[7].setSpawnMax(3);
		m_materials[7].setIdSpawn(2);

		m_materials[8].setName("iron");
		m_materials[8].setColor(dw::graphics::Colorf::Orange);
		m_materials[8].setOffsetAll(dw::maths::Vector2f(12/16.0f,9/16.0f));
		m_materials[8].setIsVoid(false);
		m_materials[8].setToughness(0.4f);
		m_materials[8].setSpawn(Material::ITEM);
		m_materials[8].setSpawnMax(5);
		m_materials[8].setIdSpawn(1);

		m_materials[9].setName("coal");
		m_materials[9].setColor(dw::graphics::Colorf::Black); // Coal
		m_materials[9].setOffsetAll(dw::maths::Vector2f(13/16.0f,9/16.0f));
		m_materials[9].setIsVoid(false);
		m_materials[9].setToughness(0.4f);
		m_materials[9].setSpawn(Material::ITEM);
		m_materials[9].setSpawnMax(5);
		m_materials[9].setIdSpawn(0);

		m_materials[10].setName("diamond");
		m_materials[10].setColor(dw::graphics::Colorf::LightBlue); // diamond	
		m_materials[10].setOffsetAll(dw::maths::Vector2f(14/16.0f,9/16.0f));
		m_materials[10].setIsVoid(false);
		m_materials[10].setToughness(0.5f);
		m_materials[10].setSpawn(Material::ITEM);
		m_materials[10].setSpawnMax(2);
		m_materials[10].setIdSpawn(4);

		m_materials[11].setName("redstone");
		m_materials[11].setColor(dw::graphics::Colorf::Red); // redstone 
		m_materials[11].setOffsetAll(dw::maths::Vector2f(15/16.0f,9/16.0f));
		m_materials[11].setIsVoid(false);
		m_materials[11].setToughness(0.5f);
		m_materials[11].setSpawn(Material::ITEM);
		m_materials[11].setSpawnMax(5);
		m_materials[11].setIdSpawn(3);

		m_materials[12].setName("glass");
		m_materials[12].setColor(dw::graphics::Colorf::White); // Glass
		m_materials[12].setOffsetAll(dw::maths::Vector2f(4/16.0f,9/16.0f));
		m_materials[12].setIsVoid(false);
		m_materials[12].setAlphaBlend(true);
		m_materials[12].setToughness(0.05f);
		m_materials[12].setSpawn(Material::NOTHING);
		m_materials[12].setSpawnMax(0);
		m_materials[12].setIdSpawn(12);

		m_materials[13].setName("woodboard");
		m_materials[13].setColor(dw::graphics::Colorf::Brown);
		m_materials[13].setOffsetAll(dw::maths::Vector2f(5/16.0f,0.0f));
		m_materials[13].setIsVoid(false);
		m_materials[13].setToughness(0.2f);
		m_materials[13].setSpawn(Material::BLOC);
		m_materials[13].setSpawnMax(1);
		m_materials[13].setIdSpawn(13);


		///////////////////////////////////////////////////////////////////////////
		////////////  ITEMBLOC
		///////////////////////////////////////////////////////////////////////////

		m_materials[14].setName("craftBox");
		m_materials[14].setOffsetTop(dw::maths::Vector2f(2/16.0f,7/16.0f));
		m_materials[14].setOffsetSide(dw::maths::Vector2f(2/16.0f,8/16.0f));
		m_materials[14].setOffsetSide2(dw::maths::Vector2f(3/16.0f,8/16.0f));
		m_materials[14].setOffsetBottom(dw::maths::Vector2f(2/16.0f,7/16.0f));
		m_materials[14].setIsVoid(false);
		m_materials[14].setAlphaBlend(false);
		m_materials[14].setToughness(0.4f);
		m_materials[14].setSpawn(Material::ITEM);
		m_materials[14].setSpawnMax(1);
		m_materials[14].setIdSpawn(14);

		m_materials[14].setName("trunk");
		m_materials[15].setColor(dw::graphics::Colorf::Brown);
		m_materials[15].setOffsetTop(dw::maths::Vector2f(5/16.0f,9/16.0f));
		m_materials[15].setOffsetSide(dw::maths::Vector2f(6/16.0f,9/16.0f));
		m_materials[15].setOffsetSide2(dw::maths::Vector2f(7/16.0f,9/16.0f));
		m_materials[15].setOffsetBottom(dw::maths::Vector2f(5/16.0f,9/16.0f));
		m_materials[15].setIsVoid(false);
		m_materials[15].setToughness(0.2f);
		m_materials[15].setSpawn(Material::ITEM);
		m_materials[15].setSpawnMax(1);
		m_materials[15].setIdSpawn(15);

		m_materialsCount = 16;
	}

	~MaterialLibrary()
	{
	}
	//! @}

public : //! @name State
	//! @{
	const Material& getDefault() const
	{
		return m_materials[0];
	}

	const dw::uint32 getMaterialCount() const 
	{
		return m_materialsCount;
	}

	const Material& getMaterialFromId(dw::uint32 id) const
	{
		if (id == 255)
			return m_materials[0];

		dwAssert(id < m_materialsCount, "Invalid parameter: id is out of range");

		return m_materials[id];
	}
	//! @}

private : //! @name Data
	//! @{
	Material m_materials[MaterialsMaxCount];
	dw::uint32 m_materialsCount;
	//! @}
};

} // namespace infinity

#endif // !INFINITY_MATERIAL_LIBRARY_H
